program mpi_hello
    ! 导入MPI库所需的模块
    use mpi
    implicit none

    integer :: ierr, rank, size
    integer :: temp_pause  ! <--- 新增的变量，用于接收输入
    logical :: debug_pause = .true. ! <--- 新增

    ! 1. 初始化 MPI 环境
    call MPI_INIT(ierr)

    ! 2. 获取进程总数 (size)
    call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr)

    ! 3. 获取当前进程排名 (rank)
    call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)

    ! ***********************************
    ! >>> 替换为 GDB 标志暂停代码 <<<
    if (rank .eq. 0) then
        print *, 'Process 0 (Master) is paused. Attach debugger, then set debug_pause=.false. to continue.'
    end if

    ! 只有主进程进入无限循环等待 GDB 修改
    if (rank .eq. 0) then
        do while (debug_pause)
            ! 循环等待，直到 GDB 改变 debug_pause 的值
            call sleep(1)
        end do
    end if

    ! 让所有进程等待 rank 0 结束等待
    call MPI_BARRIER(MPI_COMM_WORLD, ierr)
    ! ***********************************

    ! 4. 打印消息
    print *, "Hello from process ", rank, " of ", size, " total processes."
    print *, "end!"
    ! 5. 结束 MPI 环境
    call MPI_FINALIZE(ierr)

end program mpi_hello